home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / fly8111-.000 / fly8111- / fly8 / stack.c < prev    next >
C/C++ Source or Header  |  1979-12-31  |  994b  |  46 lines

  1. /* --------------------------------- stack.c -------------------------------- */
  2.  
  3. /* This is part of the flight simulator 'fly8'.
  4.  * Author: Eyal Lebedinsky (eyal@ise.canberra.edu.au).
  5. */
  6.  
  7. /* measure stack usage.
  8. */
  9.  
  10. #include "fly.h"
  11.  
  12.  
  13. #define    STACK_CHAR ((Uchar)0x5a)
  14.  
  15. extern int FAR
  16. check_stack (int func)        /* 0=set, 1=check */
  17. {
  18.     Uchar    chunk[3000], *p;
  19.  
  20.     if (func == 0) {
  21.         for (p = chunk; p < &chunk[sizeof (chunk)]; *p++ = STACK_CHAR)
  22.             ;
  23.         return (0);
  24.     }
  25.  
  26. /* If the first bytes of chunk[] are untouched then we assume that the stack
  27.  * grown to lower addresses (so chunk[] was used from its end).
  28. */
  29.     for (p = &chunk[16]; --p > chunk && *p == STACK_CHAR;)
  30.         ;
  31.  
  32.     if (p > chunk) {            /* head was used */
  33.         for (p = &chunk[sizeof (chunk)]; p > chunk;)
  34.             if (*--p != STACK_CHAR)
  35.                 return (p - chunk);
  36.     } else {                /* tail was used */
  37.         for (p = chunk; p < &chunk[sizeof (chunk)];)
  38.             if (*p++ != STACK_CHAR)
  39.                 return (sizeof (chunk) - (p - chunk));
  40.     }
  41.  
  42.     return (0);
  43. }
  44.  
  45. #undef STACK_CHAR
  46.